home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tex / macros / source / contrib / supported / xypic / src / xydoc.sty (.txt) < prev    next >
LaTeX Document  |  1995-03-15  |  31KB  |  686 lines

  1. %% $Id: xydoc.sty,v 2.12 1994/10/25 11:34:25 kris Exp $
  2. %% Style for XY-pic documentation under LaTeX.
  3. %% Copyright (c) 1993  Kristoffer H. Rose  <kris@diku.dk>
  4. %% This file is part of the XY-pic package for graphs and diagrams in TeX.
  5. %% See the companion README and INSTALL files for further information.
  6. %% Copyright (c) 1991,1992,1993     Kristoffer H. Rose  <kris@diku.dk>
  7. %% The XY-pic package is free software; you can redistribute it and/or modify
  8. %% it under the terms of the GNU General Public License as published by the
  9. %% Free Software Foundation; either version 2 of the License, or (at your
  10. %% option) any later version.
  11. %% The XY-pic package is distributed in the hope that it will be useful, but
  12. %% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13. %% or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. %% for more details.
  15. %% You should have received a copy of the GNU General Public License along
  16. %% with this package; if not, write to the Free Software Foundation, Inc.,
  17. %% 675 Mass Ave, Cambridge, MA 02139, USA.
  18. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  19. % Since the documentation files may have Danish ISO Characters...
  20. \input{latin1.sty}
  21. % ACTIVE CHARACTERS: "<|? are active (set before loading XY-pic to make the
  22. % parsing work)...and redefine LaTeX \dospecials at the same time but do NOT
  23. % tell it to redefine ? because we want to use that in code!
  24. \catcode`\"=\active
  25. \let"=\relax
  26. \catcode`\<=\active
  27. \let<=\relax
  28. \catcode`\|=\active
  29. \let|=\relax
  30. \catcode`\?=\active
  31. \let?=\relax
  32. \def\dospecials{%
  33.  \do\ \do\\\do\{\do\}\do\$\do\&\do\#\do\^\do\_\do\%\do\~\do\"\do\<\do\|}
  34. \catcode9=10
  35. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  36. % LOAD XY-pic...
  37. \makeatother
  38. \input xy
  39. \xyoption{all}
  40. \xyoption{v2}
  41. \xyoption{ps}
  42. \input xydoc.back
  43. \makeatletter
  44. \def\PStest#1#2{\ifx\empty\whichPSspecials@#1\else#2\fi}
  45. \def\PStype{\dvitype@\unskip}
  46. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  47. % TIME OF DAY
  48. \count@=\time \divide\count@ by 60\relax
  49. \count@@=\count@ \multiply\count@@ by -60 \advance\count@@ by \time
  50. \edef\now{\number\count@:\ifnum 10>\count@@ 0\fi \number\count@@}
  51. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  52. % LOGOS: METAFONT logo uses the logo10 font; AMS logo uses the math
  53. % italic font; and others just use the default font.
  54. \font\logofont=logo10
  55. \def\MF{{\logofont META}\-{\logofont FONT}}
  56. \def\AMS{{\the\textfont2 A\kern-.1667em\lower.5ex\hbox{M}\kern-.125emS}}
  57. \def\PiCTeX{P\kern-.12em\lower.5ex\hbox{I}\kern-.075emC\kern-.11em\TeX}
  58. \def\LaTeXe{{\LaTeX\kern.15em$2_{\textstyle\varepsilon}$}}
  59. \def\OzTeX{{O\kern-.03em z\kern-.15em\TeX}}
  60. \def\Textures{{\sc Textures}}
  61. \def\PS{{\sc Post\-Script}}
  62. \def\smiley{\hbox{\rlap{$\bigcirc$}\kern1.3\p@$\scriptstyle\ddot\smile$}}
  63. \def\frowny{\hbox{\rlap{$\bigcirc$}\kern1.3\p@$\scriptstyle\ddot\frown$}}
  64. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  65. % `OTHER' CHARACTERS: miscellaneous characters of category `other' ... it is
  66. % essential that space is done last!
  67. \begingroup
  68.  \catcode`\"=12 \gdef\dq{"}
  69.  \catcode`\<=12 \gdef\otherless{<}
  70.  \catcode`\>=12 \gdef\othergreater{>}
  71.  \catcode`\|=12 \gdef\otherbar{|}
  72.  \catcode`\|=0 \catcode`\<=1 \catcode`\>=2
  73.  |catcode`|\=12 |gdef|otherescape<\>
  74.  |catcode`|{=12 |gdef|otherbgroup<{>
  75.  |catcode`|}=12 |gdef|otheregroup<}>
  76.  |catcode`|$=12 |gdef|othermath<$>
  77.  |catcode`|&=12 |gdef|otherand<&>
  78.  |catcode`|#=12 |gdef|otherparameter<#>
  79.  |catcode`|^=12 |gdef|othersuper<^>
  80.  |catcode`|_=12 |gdef|othersub<_>
  81.  |catcode`|%=12 |gdef|othercomment<%>
  82.  |catcode`| =12|gdef|otherspace< >|endgroup
  83. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  84. % ABBREVIATIONS:
  85. \def\ie{{\it i}.{\it e}.} \def\Eg{{\it E}.{\it g}.}
  86. \def\eg{{\it e}.{\it g}.} \def\Ie{{\it I}.{\it e}.}
  87. \def\cf{{\it cf}.}         \def\Cf{{\it Cf}.}
  88. \def\aka{{\it aka\/}}
  89. \def\etc{{\it etc}.}
  90. % LOCAL DEFINITIONS...
  91. % \RSN, \TODO, and \DRAFT used wherever something is NOT FINISHED.
  92. \def\RSN{Real Soon Now}
  93. \def\TODO#1{{\bf To Do#1}}
  94. \def\BUG#1{{\bf Bug#1}}
  95. \def\NOTE#1{{\bf Note#1}}
  96. \def\HACK#1{{\bf Hack#1}}
  97. \def\REMARK#1{{\bf Remark#1}}
  98. \def\DRAFT#1{\framebox{\it Draft #1}\vrule width0pt height 2em depth 1em\relax}
  99. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  100. % EMPHASISING:
  101. \def"#1"{{\relax \ifmmode \mathchoice
  102.      {\hbox{\normalsize\it\relax#1\/}}%
  103.      {\hbox{\normalsize\it\relax#1\/}}%
  104.      {\hbox{\scriptsize\it\relax#1\/}}%
  105.      {\hbox{\scriptsize\it\relax#1\/}}%
  106.    \else\it#1\/\fi}}
  107. % Special `Notes' enumeration.
  108. \newcounter{note}
  109. \def\thenote{\thesection\alph{note}}
  110. \newif\ifnotes@
  111. \def\notescontd{\ifnotes@ \@toodeep \fi \notes@true
  112.  \subsubsection*{Notes}\nobreak\list{\thenote.}%
  113.  {\leftmargin=1.5pc \labelwidth=1pc \labelsep=.5pc
  114.   \usecounter{note}%
  115.   \def\makelabel##1{\thenote.\hss}}%
  116.  \expandafter\c@note\notescount@@}
  117. \def\endnotescontd{\xdef\notescount@@{\the\c@note}\endlist}
  118. \def\notes{\xdef\notescount@@{0}\notescontd}
  119. \let\note=\item
  120. \let\endnotes=\endnotescontd
  121. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  122. % DOCUMENT CLASSIFICATION...
  123. % An ``\APPENDIX'' may sometimes be a chapter of separate paper!
  124. % A ``\SECTION'' similarly!
  125. \def\APPENDIX{appendix}
  126. \def\APPENDIX{section}
  127. % Some options may prefer a ``\BIBLIOGRAPHY'' different from xydoc.bib in
  128. % plain style!
  129. \def\BIBLIOGRAPHY{%
  130.  \bibliographystyle{plain}%
  131.  \bibliography{xydoc}}
  132. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  133. % GENERIC MATH:
  134. \mathchardef\lt=\dq 313C
  135. \mathchardef\gt=\dq 313E
  136. \mathchardef\from=\dq 3220
  137. \mathcode`\*=\dq 2202
  138. \def\abs#1{\left\vert#1\right\vert}
  139. \def\floor#1{\left\lfloor#1\right\rfloor}
  140. \def\ceil#1{\left\lceil#1\right\rceil}
  141. \def\Det#1{\left\otherbar
  142.  {\arraycolsep=.2em \begin{array}{cc}#1\end{array}}\right\otherbar}
  143. % Some LaTeXs don't have this:
  144. \newbox\Boxbox@
  145. \setbox\Boxbox@=\hbox{\vrule height 5pt depth 0pt width .4pt %
  146.     \rlap{\vrule height 5pt depth -4.6pt width 4.2pt}%
  147.     \vrule height .4pt depth 0pt width 4.2pt %
  148.     \vrule height 5pt depth 0pt width .4pt}
  149. \def\Box{\relax\ifmmode\expandafter\vcenter\fi{\copy\Boxbox@}}
  150. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  151. % BNF:
  152. {\setboxz@h{$^{\hbox{\small0}}$}%
  153.  \xdef\histrut{\hbox{\vrule height\the\ht0 depth\the\dp0 width\z@}}}
  154. \def<#1>{\relax\ifmmode\histrut\expandafter\text\fi
  155.   {\rm$\langle${\ignorespaces#1}$\rangle$}}
  156. \def\iss{\relax
  157.  \ifmmode\histrut\expandafter\mathrel\fi{\hbox{$\longrightarrow$}}}
  158. \def\orr{\relax\ifmmode\histrut\expandafter\mathrel\fi{\hbox{$~\vert~$}}}
  159. \def\star{\hbox{*}}
  160. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  161. %% SHOULD USE \parbox...
  162. \leftmargin=0pt % LaTeX hack...
  163. \newenvironment{syntax}%
  164. {$$\tabskip=.5em plus1fil \dimen@=\hsize \advance\dimen@-\leftmargin
  165.  \halign to\dimen@\bgroup
  166.   \strut##\unskip\hfil&\hfil##\hfil
  167.     &##\hfil&\hsize=.5\hsize\vtop{\noindent##}\hfil\cr
  168.  \noalign{\nobreak\hrule\nobreak\smallskip}%
  169.  \multispan{3}Syntax\hfil &Action \cr
  170.  \noalign{\nobreak\smallskip\nobreak\hrule\nobreak\smallskip\nobreak}}%
  171. {\crcr\noalign{\nobreak\smallskip\nobreak\hrule\nobreak}\egroup$$%
  172.  \ignorespaces}
  173. \newenvironment{defs}%
  174. {$$\tabskip=.5em plus1fil \dimen@=\hsize \advance\dimen@-\leftmargin
  175.  \halign to\dimen@\bgroup \strut##\unskip\hfil
  176.     &\hsize=.5\hsize\vtop{\noindent##}\hfil\cr
  177.  \noalign{\hrule\nobreak\smallskip}}%
  178. {\crcr\noalign{\nobreak\smallskip\nobreak\hrule\nobreak}\egroup$$%
  179.  \ignorespaces}
  180. \newenvironment{defs1}%
  181. {$$\tabskip=.5em plus1fil \dimen@=\hsize \advance\dimen@-\leftmargin
  182.  \halign to\dimen@\bgroup \strut##\unskip\hfil\cr
  183.  \noalign{\hrule\nobreak\smallskip}}%
  184. {\crcr\noalign{\nobreak\smallskip\nobreak\hrule\nobreak}\egroup$$%
  185.  \ignorespaces}
  186. %...and the explanation inserted the first time BNF is mentioned...
  187. \newif\ifBNFuntold \BNFuntoldtrue
  188. \def\BNF{{\footnotesize BNF}%
  189.  \ifBNFuntold
  190.   \global\BNFuntoldfalse
  191.   \footnote{{\footnotesize BNF} is the notation for ``meta-linguistic
  192.     formulae'' first used in \cite{N60:ReportALA60} to describe the
  193.     syntax of the Algol programming language.  We use it with the
  194.     conventions of the \TeX\-book~\cite{K84:TeXbook}: `\iss' is read ``is
  195.     defined to be'', `\orr' is read ``or'', and `<empty>' denotes
  196.     ``nothing''; furthermore, `<id>' denotes anything that expands into a
  197.     sequence of \TeX\ character tokens, `<dimen>' and `<factor>' denote
  198.     decimal numbers with, respective without, a dimension unit (like {\tt
  199.     pt} and {\tt mm}), <number> denotes possibly signed integers, and
  200.     <text> denotes \TeX\ text to be typeset in the 
  201.     appropriate mode.  We have chosen to annotate the syntax with brief
  202.     explanations of the `action' associated with each rule; here
  203.     `$\from$' should be read `is copied from'.}%
  204.  \fi}
  205. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  206. % INLINE VERBATIM: use |...| with || in ... for a single |.  Almost not
  207. % ``fragile'' in the LaTeX sense: the ... must be a balanced token list when
  208. % ``moving'' and control sequences get an extra space except at the end...
  209. \newcount\barnest@
  210. \def|{\leavevmode\hbox\bgroup \global\barnest@=\z@
  211.  \tt \let\do\@makeother\dospecials \frenchspacing
  212.  \xyFN@\bar@}
  213. % Hack: we need to cater for both ordinary spaces (\space@) and space `other'
  214. % tokens (\otherspace)...all become simple spaces.
  215. \def\bar@{\ifx |\next \let\next@=\bar@x
  216.  \else\expandafter\ifx\otherbar\next \let\next@=\bar@x
  217.  \else\ifx \space@\next \expandafter\DN@\space{\space@\xyFN@\bar@}%
  218.  \else\expandafter\ifx \otherspace\next
  219.    \expandafter\DN@\otherspace{\space@\xyFN@\bar@}%
  220.  \else
  221.   \ifx \bgroup\next \global\advance\barnest@\@ne \fi
  222.   \ifx \egroup\next \global\advance\barnest@\m@ne \fi
  223.   \DN@{\expandafter\bar@@\string}%
  224.  \fi\fi\fi\fi \next@}
  225. \def\bar@@#1{#1\xyFN@\bar@}
  226. \def\bar@x#1{\egroup
  227.  \ifnum\z@=\barnest@\else \W@{Warning: Unbalanced \string|TEXT\string| where
  228.     \string{\string}-count is \the\barnest@}\fi
  229.  \xyFN@\rebar@}
  230. \def\rebar@{\ifx |\next \hbox{\tt\char124}\fi}
  231. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  232. % INLINE AND DISPLAYED TeX CODE:
  233. \newwrite\thecode@
  234. % Making the chunk is the most work...it goes into a temporary file that
  235. % lives while the chunk lives.
  236. \newenvironment{code}{%
  237.  \begingroup \aftergroup\endcode@
  238.   \immediate\openout\thecode@=\jobname.tmp %
  239.   \let\do\@makeother\dospecials \endlinechar=10 \futurelet\next\code@}{}
  240. \def\endcode@{\immediate\closeout\thecode@}
  241. % \code@* is the where the dirty work is done: it is called for each line in
  242. % the code chunk under construction and will finish it if that line contains
  243. % *exactly* "\end{code}".
  244. {\lccode`\0=`\\\lccode`\[=`\{\lccode`\]=`\}\lowercase{%
  245.  \expandafter\gdef\expandafter\code@\space{\code@i}
  246.  \gdef\code@i#1^^J{\code@ii#10end[code]\code@@}
  247.  \gdef\code@ii#10end[code]#2\code@@{\def\1{#1}\def\2{#2}%
  248.   \ifx\2\empty \immediate\write\thecode@{\codeof\1}\let\next@=\code@i
  249.   \else \def\next@{\oldcodes@\endgroup\end{code}}%
  250.   \fi \next@}}}
  251. \def\oldcodes@{\catcode`\\=0 \catcode`\{=1 \catcode`\}=2 \catcode`\#=6 %
  252.  \catcode`\%=14\relax}
  253. % Setting the code is just reading it...
  254. \def\gdocode{\expandafter\@@input\jobname.tmp \ifhmode\unskip\fi}
  255. \newcount\frozeninputlineno % hack to keep right file/lineno...
  256. \ifx\inputlineno\undefined
  257.  \def\docode{{\gdocode}}
  258. \else
  259. \def\docode{{\frozeninputlineno=\inputlineno
  260.   \let\@@inputlineno=\inputlineno
  261.   \def\inputlineno{\frozeninputlineno:\the\@@inputlineno}%
  262.   \gdocode}}
  263. % Showing the code is just putting TeX in verbatim mode before reading.
  264. \def\thecode{{\catcode``=13 \@noligs \let\do\@makeother \dospecials
  265.   \catcode`\ =10 \let\par\space\obeylines \frenchspacing \tt
  266.   \input\jobname.tmp \unskip}}
  267. \def\displaycode{{\inputdoc.{\jobname.tmp}}%
  268.  \ignorespaces}
  269. % Writing the code to a(nother) file is a simple combination of \code and
  270. % \showcode.
  271. \def\writecode#1{{\let\do\@makeother\dospecials \endlinechar=10 %
  272.  \def\next@{\immediate\write#1}\expandafter\writecode@\@@input\jobname.tmp }}
  273. \def\writecode@{\futurelet\next\writecode@i}
  274. \def\writecode@i{\ifx\next\egroup\else \expandafter\writecode@ii \fi}
  275. \def\writecode@ii#1^^J{\def\1{#1}\next@{\codeof\1}\futurelet\next\writecode@}
  276. \def\writecodecode#1{%
  277.  \immediate\write#1{\string\begin\string{code\string}}%
  278.  \writecode#1%
  279.  \immediate\write#1{\string\end\string{code\string}}}
  280. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  281. % EXERCISES & ANSWERS: accumulated as subsubsections on .ans file...
  282. \newif\ifExercises \Exercisesfalse
  283. \newwrite\answ@
  284. \immediate\openout\answ@=\jobname.ans
  285. \immediate\write\answ@{\othercomment\space\jobname.ans: \today, \now.}
  286. \def\exerciseprefix{}
  287. \newcount\exercisenumber \exercisenumber=0
  288. \def\restartexercises#1{\edef\exerciseprefix{#1}\exercisenumber=0 }
  289. \newenvironment{exercise}{\global\Exercisestrue
  290.  \global\advance\exercisenumber by 1 %
  291.  \edef\@currentlabel{\the\exercisenumber}%
  292.  \edef\next@{\noexpand\label{Exercise-\exerciseprefix\the\exercisenumber}}%
  293.  \next@
  294.  \paragraph*{Exercise \exerciseprefix\the\exercisenumber:}\begingroup
  295.   \def\IW@##1{\immediate\write\answ@{##1}}\IW@{}%
  296.   \IW@{\otherescape paragraph*{Answer to exercise
  297.     \exerciseprefix\the\exercisenumber\space
  298.     (p.\string\pageref{Exercise-\exerciseprefix\the\exercisenumber}):}}%
  299.   \IW@{\othercomment}}{\IW@{}\endgroup\smallbreak}
  300. \def\answertext#1{{\DN@{#1}\DNii@##1:->##2<-:{{\IW@{##2}}}%
  301.  \expandafter\nextii@\meaning\next@<-:}}
  302. \def\answercode{\writecodecode\answ@}
  303. \def\Answers{\ifExercises \Exercisesfalse \global\count1=\z@
  304.   \def\next{\immediate\closeout\answ@ \input\jobname.ans
  305.    \immediate\openout\answ@=\jobname.ans
  306.    \immediate\write\answ@{\othercomment\space\jobname.ans: \today, \now.}}%
  307.   \expandafter\next\fi}
  308. \def\ANSWERS{\ifExercises
  309.  \section*{Answers to all exercises}
  310.  \addcontentsline{toc}{section}{Answers to all exercises}
  311.  \Answers
  312. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  313. % PRINTING MACRO FILES AS DOCUMENTATION
  314. % \inputdoc <type> {<file>}  will read <file>.doc, extracting either
  315. % * a verbatim input file with line numbers if <type> is 0 (ignoring \DOCMODE
  316. %   commands in the file),
  317. % * the reference manual body if <type> is the character 1, or
  318. % * the TeXnical documentation body if <type> is the character 2.
  319. % For the second and third types to work, <file>.doc must have the structure
  320. %    <header>
  321. %    \DOCMODE<mode>
  322. %    <stuff>
  323. %    \DOCMODE<mode>
  324. %    <stuff>
  325. %    \DOCMODE3
  326. %    <stuff>
  327. % where each <mode> can be either of the characters
  328. % 0 to designate that the following <stuff> should be ignored,
  329. % 1 to designate that the following <stuff> is TeX source material to
  330. %   be included only in the reference manual,
  331. % 2 to designate that the following <stuff> is TeX source material to
  332. %   be included only in the TeXnical documentation,
  333. % 3 to designate that the following <stuff> is TeX source material to
  334. %   be included in the reference manual and the TeXnical document,
  335. % . for unnumbered program file listing
  336. % : for numbered program file listing
  337. % ! for stuff in the same mode as the context
  338. % ( to designate that the following <stuff> is code that is included in
  339. %   <file>.tex that should also be typeset verbatim in the TeXnical document,
  340. %   or
  341. % ) to designate that the following <stuff> is of the same kind as the
  342. %   <stuff> preceeding the most recent \DOCMODE).
  343. % Furthermore, the command \DOCHEADER is available after the first \DOCMODE2
  344. % command to insert the <header> verbatim.  The last command must be
  345. % \DOCMODE3 in order to ensure that the end of the file is seen by both
  346. % document types!
  347. % Finally the reference PREFIX is set to the file name so that `global'
  348. % references across files are possible...
  349. % The <file>.tex to be distributed should include the <header> and all
  350. % <stuff> between \DOCMODE( and \DOCMODE).
  351. \let\thedocmode@=0
  352. \let\defaultinputdocmode=:
  353. % \inputdoc MODE {FILE}  loads FILE in docmode MODE.  0 means
  354. \gdef\inputdoc#1#2{%
  355.  \mayshrinktt@true
  356.  \if#1!\relax \let\next=\defaultinputdocmode \fi
  357.  \if#10\relax \numbercode@true \let\DocMode@=\docmode@@@
  358.  \else\if#11\relax \let\DocMode@=\docmode@
  359.  \else\if#12\relax \let\DocMode@=\docmode@@
  360.  \else\if#1:\relax \mayshrinktt@false\numbercode@true \let\DocMode@=\docmode@@@
  361.  \else\if#1.\relax \mayshrinktt@false\numbercode@false\let\DocMode@=\docmode@@@
  362.  \fi\fi\fi\fi\fi
  363.  {\questprefix{#2}\expandafter\let\csname DOCMODE\endcsname=\DocMode@
  364.   \endlinechar=`\^^J%
  365.   \def\next@{\csname DOCMODE\endcsname @}\expandafter\next@\@@input#2 }%
  366.  \ifmayshrinktt@\medbreak\fi}
  367. \let\^^J=\ % such that `\ ' works at end of line!
  368. % First variant is for the reference manual: ignore everything except lines
  369. % with MODE 1 or 3.
  370. \let\lastdocmode@=0
  371. \def\docmode@#1{%
  372.  \ifx#11\let\next@=\relax \let\lastdocmode@=1\relax
  373.  \else\ifx#12\let\next@=\docs@ \let\lastdocmode@=2\relax
  374.  \else\ifx#13\let\next@=\relax \let\lastdocmode@=3\relax
  375.  \else\ifx#1@\let\next@=\docs@
  376.  \else\ifx#1(\let\next@=\docs@
  377.  \else\ifx#1)\DN@{\docmode@\lastdocmode@}%
  378.  \else\let\next@=\docs@ \let\lastdocmode@=0\relax
  379.  \fi\fi\fi\fi\fi\fi \next@}
  380. % Second variant is for the technical docs: typeset everything normally
  381. % except areas with MODE ( that are typeset verbatim, areas with MODE 0,
  382. % and 1 which are ignored, and areas with MODE @ which are stuffed into a
  383. % file (used for the \DOCHEADER feature):
  384. \def\docmode@@#1{%
  385.  \ifx#11\let\next@=\docs@ \let\lastdocmode@=1\relax
  386.  \else\ifx#12\let\next@=\relax \let\lastdocmode@=2\relax
  387.  \else\ifx#13\let\next@=\relax \let\lastdocmode@=3\relax
  388.  \else\ifx#1@\let\next@=\docc@
  389.  \else\ifx#1(\let\next@=\docv@
  390.  \else\ifx#1)\DN@{\docmode@@\lastdocmode@}%
  391.  \else\let\next@=\docs@ \let\lastdocmode@=0\relax
  392.  \fi\fi\fi\fi\fi\fi \next@}
  393. % Third is for verbatim...
  394. \def\docmode@@@#1{\docv@}
  395. % Here are the three interpretation macros: first one that skips...
  396. \def\docs@{%
  397.  \begingroup\skipspecials@ \let\docm@=\docm@i \let\docecho@=\relax
  398.  \def\docfinish@{\global\let\thedocmode@=\next
  399.   \endgroup \xyuncatcodes \csname DOCMODE\endcsname\thedocmode@}%
  400.  \docm@}
  401. % ..then the one that typesets verbatim: it needs a special hack to be able
  402. % to recognize the end of files when using \inputdoc0...
  403. \newif\ifnumbercode@        % number lines!
  404. \def\lineno@{\ifx\inputlineno\undefined\else\the\inputlineno\fi}
  405. \def\docv@{%
  406.  \par\vspace{1ex}\begingroup \skipspecials@
  407.  \def\docm@{\xyFN@\docvm@}%
  408.  \def\docvm@{\ifx\next\egroup \DN@{\endgroup\par\vspace{1ex}}%
  409.   \else \let\next@\docm@i \fi \next@}%
  410.  \parfillskip\@flushglue \parskip\z@ \def\par{}\obeylines\tt
  411.  \catcode``=13 \@noligs \let\do\@makeother\dospecials
  412.  \catcode`\%=13 %make % act as ?...
  413.  \frenchspacing\@vobeyspaces \activateTABandFF@
  414.  \def\docecho@{\ifx\next\empty\vspace{1ex}\else
  415.    \hbox{%
  416.     \ifnumbercode@\hbox to 1.5pc{\tinyrm\lineno@\hss}%
  417.     \else\hbox to\leftmargin{\hss}\fi
  418.     \setbox0=\hbox\bgroup\next\egroup\box0}\fi}%
  419.  \def\docfinish@{\global\let\thedocmode@=\next \endgroup
  420.   \xyuncatcodes \par\vspace{1ex}\csname DOCMODE\endcsname\thedocmode@}%
  421.  \docm@}
  422. \def\tinyrm{\tiny\rm}
  423. % ...with some trickery to get TABs interpreted right:
  424. \newdimen\tabw@
  425. \def\activeTAB@{\egroup \dimen@=\wdz@
  426.  \divide\dimen@\tabw@ \multiply\dimen@\tabw@ \advance\dimen@\tabw@
  427.  \wdz@=\dimen@ \boxz@ \setboxz@h\bgroup}%
  428. \def\activeFF@{\egroup
  429.  \dimen@=\hsize \advance\dimen@-\wdz@ \advance\dimen@-2pc %
  430.  \boxz@ \raise.7ex\hbox to\dimen@{\hrulefill}\setboxz@h\bgroup}
  431. % They are activated by \activateTABandFF@ that also picks a \tt font size
  432. % that will allow 77 characters = 9.7 tabstops per line propvided the
  433. % conditional mayshrinktt@ is true...
  434. \newif\ifmayshrinktt@
  435. {\catcode`\^^I=\active \catcode`\^^L=\active \let^^L=\par
  436.  \gdef\activateTABandFF@{\setboxz@h{00000000}\tabw@=\wdz@ \dimen@=\hsize
  437.   \ifnumbercode@ \advance\dimen@-1.5pc \fi
  438.   \ifmayshrinktt@
  439.    \ifdim 9.7\tabw@>\dimen@\small\tt\setboxz@h{00000000}\tabw@=\wdz@\fi
  440.    \ifdim 9.7\tabw@>\dimen@\footnotesize\tt\setboxz@h{00000000}\tabw@=\wdz@\fi
  441.   \fi
  442.   \catcode`\^^I=\active \let^^I=\activeTAB@
  443.   \catcode`\^^L=\active \let^^L=\activeFF@ }}
  444. % ...and finally one that makes code out of the block:
  445. \def\docc@{%
  446.  \par\begingroup \skipspecials@ \let\docm@=\docm@i
  447.  \def\par{}\obeylines \catcode``=13 \@noligs \let\do\@makeother \dospecials
  448.  \@vobeyspaces \immediate\openout\thecode@=\jobname.tmp %
  449.  \def\docecho@{{\immediate\write\thecode@{\codeof\next}}}%
  450.  \def\docfinish@{\immediate\closeout\thecode@ \global\let\thedocmode@=\next
  451.   \endgroup\xyuncatcodes \csname DOCMODE\endcsname\thedocmode@}%
  452.  \docm@}
  453. \def\DOCHEADER{%
  454.  \numbercode@true \inputdoc0{\jobname.tmp}}
  455. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  456. % CROSS REFERENCES AND INDEXING AND SUCH
  457. % Use ?? as a cross reference code -- even in verbatim (because ? is excluded
  458. % from \dospecials in the header):
  459. %    ?? <codes> [ <id> ]
  460. % will create a reference and/or label and/or index entry and possibly even
  461. % typeset <id>---what is done depends on <codes> that should be a sequence of
  462. % characters selected from the following:
  463. %    !    typeset <id>
  464. %    -    do nothing*
  465. %    :    set PREFIX to <id> and do \mylabel{PREFIX:}*
  466. %    =    as \mylabel{PREFIX:<id>}*
  467. %    ?    as \myref{PREFIX:<id>}*
  468. %    ^    \myref{PREFIX:<id>} lifted as superscript*
  469. %    _    \myref{PREFIX:<id>} in \tinyrm font*
  470. %    g    global: set PREFIX to null temporarily
  471. %    p    as \mypageref{PREFIX:<id>}*
  472. %    w    as \index{<id>}            for words
  473. %    c    as \index{\string<id>}        for control sequences
  474. %    v    as \index{"<id>"}        for variables
  475. %       *    as \mylinelabel{<id>}
  476. % If none of the <codes> letters was a *ed one then a \myref{PREFIX:<id>} is
  477. % added automatically (so ??[<id>] gives a simple reference).
  478. % NOTE: Use VERY PRIVATE names for *everything* because ??s may occur
  479. % *everywhere* !!  Also before loading \XY-pic because we need to bind ?.
  480. \def?{\let\questchar@=\otherquest@ \futurelet\questnext@\quest@}
  481. \newif\ifquestdone@
  482. {\catcode`\%=\active
  483.  \gdef%{\let\questchar@=\otherpercent@ \futurelet\questnext@\quest@}}
  484. {\catcode`\?=12 \catcode`\%=12 \gdef\otherquest@{?}\gdef\otherpercent@{%}}
  485. \def\quest@{\ifx ?\questnext@ \def\questnext@?{\quest@@}%
  486.  \else \let\questnext@=\questchar@ \fi \questnext@}
  487. \def\quest@@#1[#2]{\questdone@false
  488.  \let\questref@=\myref \let\questpageref@=\mypageref
  489.  \let\questecho@@=\relax \def\doquest@##1{{##1{#2}}}\quest@@@#1@}
  490. \def\quest@@@#1{\relax
  491.  \ifx @#1\def\questnext@{\ifquestdone@\else \doquest@\questref@ \fi}%
  492.  \else\ifx !#1\def\questnext@{\doquest@\questecho@@ \quest@@@}%
  493.  \else\ifx -#1\def\questnext@{\questdone@true \quest@@@}%
  494.  \else\ifx :#1\def\questnext@{\doquest@\questprefix \questdone@true \quest@@@}%
  495.  \else\ifx =#1\def\questnext@{\doquest@\mylabel \questdone@true \quest@@@}%
  496.  \else\ifx ?#1\def\questnext@{\doquest@\questref@ \questdone@true \quest@@@}%
  497.  \else\ifx g#1\def\questnext@{%
  498.    \let\questref@=\globalref \let\questpageref@=\globalpageref \quest@@@}%
  499.  \else\ifx ^#1\def\questnext@{\doquest@\liftedref@ \questdone@true \quest@@@}%
  500.  \else\ifx _#1\def\questnext@{\doquest@\mylineref \questdone@true \quest@@@}%
  501.  \else\ifx p#1\def\questnext@{\doquest@\questpageref@ \questdone@true
  502.    \quest@@@}%
  503.  \else\ifx w#1\def\questnext@{\doquest@\index \questdone@true \quest@@@}%
  504.  \else\ifx c#1\def\questnext@{\doquest@{\index code}\questdone@true
  505.    \let\questecho@@=\codeecho@ \quest@@@}%
  506.  \else\ifx *#1\def\questnext@{\doquest@\mylinelabel \questdone@true \quest@@@}%
  507.  \else \def\questnext@##1{\xyerror@{\string?\string?\string##1 undefined}}%
  508.  \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi \questnext@}
  509. \def\liftedref@#1{$^{\hbox{\small\questref@{#1}}}$}
  510. \def\questprefix#1{\def\questprefix@@{#1}}
  511. \def\questprefix@@{}
  512. \def\codeecho@#1{\ifmmode\expandafter\hbox\fi{\DN@{#1}\tt\codeof\next@\unskip}}
  513. % REPLACEMENT for LaTeX cross reference macros...using \codeof...
  514. \def\mylabel#1{\@bsphack \if@filesw {%
  515.  \expandafter\DN@\expandafter{\questprefix@@:#1}\let\thepage\relax
  516.    \def\protect{\noexpand\noexpand\noexpand}%
  517. \xdef\@gtempa{\write\@auxout{\string
  518.       \newlabel{\codeof\next@}{{\@currentlabel}{\thepage}}}}}\@gtempa
  519.    \if@nobreak \ifvmode\nobreak\fi\fi\fi\@esphack}
  520. \def\mylinelabel#1{\@bsphack \if@filesw {%
  521.  \expandafter\DN@\expandafter{\questprefix@@:#1}\let\thepage\relax
  522.    \def\protect{\noexpand\noexpand\noexpand}%
  523. \xdef\@gtempa{\write\@auxout{\string
  524.  \newlabel{\codeof\next@}{{l.\thelineno@}{\thepage}}}}}\@gtempa
  525.    \if@nobreak \ifvmode\nobreak\fi\fi\fi\@esphack}
  526. %Was:
  527. %\def\label#1{\@bsphack\if@filesw {\let\thepage\relax
  528. %   \def\protect{\noexpand\noexpand\noexpand}%
  529. %\xdef\@gtempa{\write\@auxout{\string
  530. %      \newlabel{#1}{{\@currentlabel}{\thepage}}}}}\@gtempa
  531. %   \if@nobreak \ifvmode\nobreak\fi\fi\fi\@esphack}
  532. \def\myref#1{\expandafter\globalref\expandafter{\questprefix@@:#1}}
  533. \def\mylineref#1{\hbox{\tinyrm\questref@{#1}}}
  534. \def\globalref#1{\DN@{#1}%
  535.  \edef\next@{\codeof\next@}%
  536.  \@ifundefined{r@\next@}{{\bf \string?\string?}%
  537.    \@warning{Reference `\next@' on page \thepage\space undefined}}%
  538.   {\edef\@tempa{\@nameuse{r@\next@}}\expandafter
  539.     \@car\@tempa \@nil\null}}
  540. %Was:
  541. %\def\ref#1{\@ifundefined{r@#1}{{\bf ??}\@warning
  542. %   {Reference `#1' on page \thepage \space
  543. %    undefined}}{\edef\@tempa{\@nameuse{r@#1}}\expandafter
  544. %    \@car\@tempa \@nil\null}}
  545. \def\mypageref#1{\expandafter\globalpageref\expandafter{\questprefix@@:#1}}
  546. \def\globalpageref#1{\DN@{#1}%
  547.  \edef\next@{\codeof\next@}%
  548.  \@ifundefined{r@\next@}{{\bf \string?\string?}%
  549.    \@warning{Reference `\next@' on page \thepage\space undefined}}%
  550.   {\edef\@tempa{\@nameuse{r@\next@}}\expandafter
  551.     \@cdr\@tempa \@nil\null}}
  552. %Was:
  553. %\def\pageref#1{\@ifundefined{r@#1}{{\bf ??}\@warning
  554. %   {Reference `#1' on page \thepage \space
  555. %    undefined}}{\edef\@tempa{\@nameuse{r@#1}}\expandafter
  556. %    \@cdr\@tempa\@nil\null}}
  557. % \newlabel *is* redefined because LaTeX plays tricks with it at
  558. % \end{document}.
  559. \def\newlabel#1#2{\DN@{#1}\edef\next@{\codeof\next@}%
  560.  \@ifundefined{r@\next@}{}{\@warning{Label `#1' multiply
  561.    defined}}\global\@namedef{r@\next@}{#2}}
  562. % Was:
  563. %\def\newlabel#1#2{\@ifundefined{r@#1}{}{\@warning{Label `#1' multiply
  564. %   defined}}\global\@namedef{r@#1}{#2}}
  565. \def\@testdef #1#2#3{\DN@{#2}\edef\next@{\codeof\next@}%
  566.  \def\@tempa{#3}\expandafter \ifx \csname #1@\next@\endcsname
  567.  \@tempa  \else \@tempswatrue \fi}
  568. % Was:
  569. %\def\@testdef #1#2#3{\def\@tempa{#3}\expandafter \ifx \csname #1@#2\endcsname
  570. % \@tempa  \else \@tempswatrue \fi}
  571. % Here is our variant \index command: It is a hack made such that 
  572. %Dummy eats pre-{} argument
  573. \def\index#1#{\@bsphack\begingroup \@sanitize\@index}
  574. %Real stuff uses pre-{} argument
  575. \def\@wrindex#1#{\@wrindex@{#1}}
  576. \def\@wrindex@#1#2{\let\thepage\relax
  577.  \DN@{#2}%
  578.  \edef\@tempa{\write\@indexfile{%
  579.   \expandafter\string\csname indexentry#1\endcsname{\codeof\next@}{\thepage}}}%
  580.  \expandafter\endgroup\@tempa
  581.  \if@nobreak \ifvmode\nobreak\fi\fi\@esphack}
  582. % After sorting the index it contains...
  583. \def\INDEX{\begin{theindex}\label{INDEX}
  584.  \input{\jobname.ind}
  585.  \end{theindex}}
  586. \def\indexlast@{}
  587. \def\indexentry#1#2{\DN@{#1}%
  588.  \ifx\next@\indexlast@ \DNii@{, }%
  589.  \else \DNii@{\item #1\unskip\quad}\let\indexlast@=\next@ \fi
  590.  \nextii@ #2}
  591. \def\indexentrycode{\xycatcodes\indexentrycode@}
  592. \def\indexentrycode@#1#2{\DN@{#1}\edef\next@{\codeof\next@}%
  593.  \ifx\next@\indexlast@ \DNii@{\unskip, }%
  594.  \else \DNii@{\item {\tt\next@\unskip}\quad}\let\indexlast@=\next@ \fi
  595.  \nextii@ #2\xyuncatcodes}
  596. \def\macroentry{\xycatcodes\macroentry@}
  597. \def\macroentry@#1#2#3{\DN@{#1}\edef\next@{\codeof\next@}%
  598.  \ifx\next@\indexlast@ \DNii@{\unskip,\space\linebreak[3]}%
  599.  \else \DNii@{\item{\tt\next@\unskip}\quad}\let\indexlast@=\next@ \fi
  600.  \nextii@ {\tt#2}:{\tinyrm#3}\xyuncatcodes}%
  601. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  602. % Set page size to A4...with sligthly wider text when two columns
  603. \if@twocolumn
  604.  \setlength{\oddsidemargin}{-0.56cm}
  605.  \setlength{\evensidemargin}{-0.56cm}
  606.  \setlength{\textwidth}{17cm}
  607. \else
  608.  \setlength{\oddsidemargin}{0.46cm}
  609.  \setlength{\evensidemargin}{0.46cm}
  610.  \setlength{\textwidth}{15cm}
  611. \setlength{\topmargin}{-1.4cm}
  612. \setlength{\headheight}{0.7cm}
  613. \setlength{\headsep}{0.7cm}
  614. \setlength{\textheight}{23.7cm}
  615. %\setlength{\footheight}{0.7cm}
  616. \setlength{\footskip}{1.1cm}
  617. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  618. % Tracing auxiliary
  619. \def\notracingall{\tracingonline\z@\tracingcommands\z@\tracingstats\z@
  620.   \tracingpages\z@\tracingoutput\z@\tracinglostchars\z@
  621.   \tracingmacros\z@\tracingparagraphs\z@\tracingrestores\z@
  622.   \showboxbreadth5 \showboxdepth5}
  623. % Show bad boxes as plain TeX!
  624. \hbadness=1000
  625. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  626. % RCS date...
  627. \def\printdate#1{\edef\next@{#1}\expandafter\printdate@\next@ @}
  628. \def\printdate@#1/#2/#3@{%
  629.  \ifcase#2\or January\or February\or March\or April\or
  630.   May\or June\or July\or August\or September\or October\or November\or
  631.   December\fi\space
  632.  \eatzero@#3, \ifnum100>#1\relax19\fi#1}
  633. \def\eatzero@#1{\ifx0#1\else#1\fi}
  634. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  635. % END OF DEFINITIONS
  636. \endinput
  637. $Log: xydoc.sty,v $
  638. Revision 2.12  1994/10/25  11:34:25  kris
  639. Interim release just before v3 [works with AMS-LaTeX 1.2]...
  640. Revision 2.11  1994/07/05  10:37:32  kris
  641. Third 3beta release [bug fixes].
  642. Experimental graph feature included (for ECCT-94 presentation).
  643. Revision 2.10  1994/06/15  12:55:07  kris
  644. Second 3beta release: bug fixes.
  645. Revision 2.9  1994/06/09  14:59:19  kris
  646. Release 3beta.
  647. Revision 2.8.3.8  1994/05/05  06:13:13  kris
  648. Compilation works and is documented.
  649. Matrix object outline bug fixed.
  650. Revision 2.8.3.7  1994/05/04  08:16:25  kris
  651. Also has option depedency list now.
  652. Revision 2.8.3.6  1994/05/04  07:14:13  kris
  653. Compiling matrices work :-) :-) !!
  654. Revision 2.8.3.5  1994/05/04  03:51:05  kris
  655. Efficient queueing *and* compilation of matrices *almost* there :-) !!
  656. Revision 2.8.3.4  1994/05/03  12:42:52  kris
  657. Compiling of matrices soon to follow :-) ...
  658. Revision 2.8.3.3  1994/05/03  11:01:35  kris
  659. Compiling to file finished in kernel...
  660. Revision 2.8.3.2  1994/05/03  07:37:06  kris
  661. Fiddling for 2.9...
  662. Revision 2.8.3.1  1994/04/19  08:15:02  kris
  663. Going on holiday...
  664. Revision 2.8.1.2  1994/04/13  11:44:13  kris
  665. PostScript update patch and various fixes...
  666. Revision 2.8  1994/04/08  04:30:00  kris
  667. Second (bug fix) 3alpha release.
  668. Revision 2.7.2.4  1994/03/28  10:58:05  kris
  669. Curve bugs fixed [Ross].
  670. Edge logic overhauled...still shaky?
  671. PostScript added and maybe working!
  672. Revision 2.7.2.3  1994/03/28  04:07:38  kris
  673. Holiday is over :-)
  674. Revision 2.7.2.2  1994/03/13  07:54:52  kris
  675. Bug fixes and @@ `map over stack'.
  676. Revision 2.7.2.1  1994/03/11  11:47:11  kris
  677. Documentation prettyfied.
  678. Stacks added.
  679. Revision 2.7.1.1  1994/03/10  05:26:53  kris
  680. Date format fixed.
  681. Revision 2.7  1994/03/08  02:06:01  kris
  682. Release 3alpha.
  683. Revision 2.6.9.1  1994/03/07  04:22:46  kris
  684. Last internal 3alpha and pre-2.7 release.
  685. NEW for XY-pic version 2.7.
  686.